

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *

# import resources

from googlemaps import googleMap,googleSettings
from geonames import gnExtended
from osm import osmMap,osmeditMap,osmSettings
from flickrMap import flickrPics,flickrSettings
from bingmaps import bingMap, bingSettings
from geoHack import geoHack

from clickFuUtils import cfTool

clickHacks = [googleMap, gnExtended, osmMap, osmeditMap, bingMap, flickrPics, geoHack]
clickSettings = [googleSettings, osmSettings, flickrSettings, bingSettings]

import doAbout, doSettings

class MainPlugin(object):
  def __init__(self, iface):
    # Save a reference to the QGIS iface
    self.iface = iface

  def initGui(self):
    # Create action
    self.menu=QMenu("Click-fu")

    self.clickActions = [  x(self.iface) for x in clickHacks ]

    self.about = QAction("About ClickFu",self.iface.mainWindow())
    QObject.connect(self.about,SIGNAL("triggered()"),self.clickAbout)

    self.activate=QAction("Activate",self.iface.mainWindow())
    QObject.connect(self.activate,SIGNAL("triggered()"),self.gogogo)
    self.menu.addAction(self.activate)

#     self.active = QMenu("Active")
#     self.active.addActions(self.clickActions)
    
#     for action in self.clickActions:
#       if QSettings().value("/clickfu/set/"+action.name()).toBool():
#         action.setChecked(True)

#     self.menu.addMenu(self.active)


    self.settings = QMenu("Settings")

    self.globalSettings = QAction("Global",self.iface.mainWindow())
    QObject.connect(self.globalSettings,SIGNAL("triggered()"),self.globalSet)
    self.settings.addAction(self.globalSettings)
    self.settings.addSeparator()
    for a in clickSettings:
      action = a(self.iface)
      self.settings.addAction(action)
    self.menu.addMenu(self.settings)

    self.menu.addSeparator()
    self.menu.addAction(self.about)

      
    menuBar = self.iface.mainWindow().menuBar()
    menuBar.addMenu(self.menu)

  def clickAbout(self):
    d = doAbout.Dialog()
    d.exec_()

  def unload(self):
    # Remove the plugin
    pass

  def gogogo(self):
    self.tool=cfTool(self.iface,self.clickActions)
    self.iface.mapCanvas().setMapTool(self.tool)

  def globalSet(self):
    d = doSettings.Dialog(self.clickActions)
    d.exec_()
